Skip to content

improvement: Rework IndexedContext to reuse the previously calculated scopes - #22898

Merged
tgodzik merged 2 commits into
scala:mainfrom
tgodzik:fix-slow
Apr 25, 2025
Merged

tgodzik merged 2 commits into
scala:mainfrom
tgodzik:fix-slow

Conversation

@tgodzik

@tgodzik tgodzik commented Apr 1, 2025 •

Copy link
Copy Markdown
Contributor

It turns out the work being done in IndexedContext was already done in Completions, but better, since it doesn't try to read files as the separate logic does.

There is still some improvement to be done to not calculate it twice, but in order to keep this PR as simple as possible I will skip that for now.

@som-snytt

som-snytt commented Apr 1, 2025 •

Copy link
Copy Markdown
Contributor

I wonder if this strategy helps #22430 (which I haven't returned to yet)

Edit: I guess only in the sense of "moral support".

@tgodzik

tgodzik commented Apr 1, 2025

Copy link
Copy Markdown
Contributor Author

I think I am actually doing it all wrong and might be possible that IndexedContext is not really needed 😅

@tgodzik
tgodzik force-pushed the fix-slow branch 2 times, most recently from 3e69d9e to 21aa3b8 Compare April 3, 2025 18:27
@tgodzik
tgodzik force-pushed the fix-slow branch 4 times, most recently from d27ca2c to 376f628 Compare April 16, 2025 20:05
@tgodzik tgodzik changed the title improvement: Look up isAccessible lazily improvement: Rework IndexedContext to reuse the previously calculated scopes Apr 16, 2025
… scopes

It turns out the work being done in IndexedContext was already done in Completions, but better, since it doesn't try to read files as the separate logic does.

There is still some improvement to be done to not calculate it twice, but in order to keep this PR as simple as possible I will skip that for now.

object Completion:

def scopeContext(pos: SourcePosition)(using Context): CompletionResult =

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally this would get deduplicated with normal rawCompletions being invoked, but I will try to do it as a separate step afterwards.

"""
|object A {
| val e: Either[Int, String] = ???
| type Left = String

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

type val actually fine here, but val causes an error

| ???
| }
| val x/*: AB<<scala/collection/AbstractMap#>>[Int<<scala/Int#>>, String<<scala/Predef.String#>>]*/ = test(Set/*[Int<<scala/Int#>>]*/(1), Set/*[Char<<scala/Char#>>]*/('a'))
| val x/*: AB<<scala/collection/AbstractMap#>>[Int<<scala/Int#>>, String<<java/lang/String#>>]*/ = test(Set/*[Int<<scala/Int#>>]*/(1), Set/*[Char<<scala/Char#>>]*/('a'))

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was inconsistent previously

@tgodzik
tgodzik requested review from kasiaMarek and rochala April 17, 2025 10:18
@tgodzik
tgodzik marked this pull request as ready for review April 17, 2025 10:18

@kasiaMarek kasiaMarek left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some nitpicks and questions, but overall looks really cool 🎉

Comment thread presentation-compiler/src/main/dotty/tools/pc/IndexedContext.scala Outdated
Comment thread presentation-compiler/src/main/dotty/tools/pc/IndexedContext.scala Outdated
Comment thread presentation-compiler/src/main/dotty/tools/pc/IndexedContext.scala Outdated
if !id.symbol.is(Synthetic) && !id.symbol.is(Implicit) =>
symbols + tree.symbol
case sel: Select =>
indexedContext.lookupSym(sel.symbol) match

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm questioning this right now. Shouldn't we actually just collect the symbol of the qualifier? (Sort of a side comment not connected to the PR)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was causing the + method etc. to be reported as conflicting, which was not really a problem.

Comment thread presentation-compiler/src/main/dotty/tools/pc/IndexedContext.scala
@tgodzik
tgodzik requested a review from kasiaMarek April 25, 2025 13:50

@kasiaMarek kasiaMarek left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@tgodzik
tgodzik merged commit 9d90ff5 into scala:main Apr 25, 2025
@tgodzik
tgodzik deleted the fix-slow branch April 25, 2025 15:18
tgodzik added a commit to scala/scala3-lts that referenced this pull request Apr 28, 2025
… scopes (scala#22898)

It turns out the work being done in IndexedContext was already done in
Completions, but better, since it doesn't try to read files as the
separate logic does.

There is still some improvement to be done to not calculate it twice,
but in order to keep this PR as simple as possible I will skip that for
now.
tgodzik added a commit to scala/scala3-lts that referenced this pull request Apr 28, 2025
… scopes (scala#22898)

It turns out the work being done in IndexedContext was already done in
Completions, but better, since it doesn't try to read files as the
separate logic does.

There is still some improvement to be done to not calculate it twice,
but in order to keep this PR as simple as possible I will skip that for
now.
[Cherry-picked 9d90ff5][modified]
tgodzik added a commit to scala/scala3-lts that referenced this pull request Apr 29, 2025
… scopes (scala#22898)

It turns out the work being done in IndexedContext was already done in
Completions, but better, since it doesn't try to read files as the
separate logic does.

There is still some improvement to be done to not calculate it twice,
but in order to keep this PR as simple as possible I will skip that for
now.
tgodzik added a commit to scala/scala3-lts that referenced this pull request Apr 29, 2025
… scopes (scala#22898)

It turns out the work being done in IndexedContext was already done in
Completions, but better, since it doesn't try to read files as the
separate logic does.

There is still some improvement to be done to not calculate it twice,
but in order to keep this PR as simple as possible I will skip that for
now.
[Cherry-picked 9d90ff5][modified]
tgodzik added a commit to scala/scala3-lts that referenced this pull request Apr 30, 2025
… scopes (scala#22898)

It turns out the work being done in IndexedContext was already done in
Completions, but better, since it doesn't try to read files as the
separate logic does.

There is still some improvement to be done to not calculate it twice,
but in order to keep this PR as simple as possible I will skip that for
now.
tgodzik added a commit to scala/scala3-lts that referenced this pull request Apr 30, 2025
… scopes (scala#22898)

It turns out the work being done in IndexedContext was already done in
Completions, but better, since it doesn't try to read files as the
separate logic does.

There is still some improvement to be done to not calculate it twice,
but in order to keep this PR as simple as possible I will skip that for
now.
[Cherry-picked 9d90ff5][modified]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants